package com.imay.live.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.imay.live.R;
import com.imay.live.utils.GlideUtil;
import com.imay.live.utils.ViewUtil;

import java.util.List;

/**
 * Created by Administrator on 2017/8/31 0031.
 */

public class FamilyItemViewRound extends RelativeLayout implements View.OnClickListener {

    TextView tv_item_title;
    TextView tv_item_count;
    ImageView civ_item_family_home_img_1;
    ImageView civ_item_family_home_img_2;
    ImageView civ_item_family_home_img_3;

    View tv_family_shortlive_nodata, tv_family_feed_nodata, tv_family_shortlive_in;

    private OnNodataClick onNodataClick;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_family_shortlive_in:
                if (onNodataClick != null) {
                    onNodataClick.noDataClick();
                }
                break;
        }
    }

    public interface OnNodataClick {
        void noDataClick();
    }

    public OnNodataClick getOnNodataClick() {
        return onNodataClick;
    }

    public void setOnNodataClick(OnNodataClick onNodataClick) {
        this.onNodataClick = onNodataClick;
    }


    public FamilyItemViewRound(Context context) {
        this(context, null);
    }

    public FamilyItemViewRound(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FamilyItemViewRound(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        LayoutInflater.from(context).inflate(R.layout.view_family_item_round, this, true);

        init();
    }

    private void init() {
        tv_item_title = ViewUtil.findView(this, R.id.tv_item_title);
        tv_item_count = ViewUtil.findView(this, R.id.tv_item_count);
        tv_family_shortlive_nodata = ViewUtil.findView(this, R.id.tv_family_shortlive_nodata);
        tv_family_feed_nodata = ViewUtil.findView(this, R.id.tv_family_feed_nodata);
        tv_family_shortlive_in = ViewUtil.findView(this, R.id.tv_family_shortlive_in);
        tv_family_shortlive_in.setOnClickListener(this);
//        int bordwidth = (int) getResources().getDimension(R.dimen.dp_4);
//        int color = Color.WHITE;
//        int width = (int) getResources().getDimension(R.dimen.size_60dp);
//        int height = (int) getResources().getDimension(R.dimen.size_60dp);
//
        civ_item_family_home_img_1 = ViewUtil.findView(this, R.id.civ_item_family_home_img_1);
//        GlideUtil.loadImageView(getContext(), "http://img.imay.com/head-36209-1504698517-2297.jpg",
//                civ_item_family_home_img_1);
//
        civ_item_family_home_img_2 = ViewUtil.findView(this, R.id.civ_item_family_home_img_2);
//        GlideUtil.loadImageView(getContext(), "http://img.imay.com/head-36209-1504698517-2297.jpg",
//                civ_item_family_home_img_2);
//
        civ_item_family_home_img_3 = ViewUtil.findView(this, R.id.civ_item_family_home_img_3);
//        GlideUtil.loadImageView(getContext(), "http://img.imay.com/head-36209-1504698517-2297.jpg",
//                civ_item_family_home_img_3);
        civ_item_family_home_img_1.setClickable(false);
        civ_item_family_home_img_2.setClickable(false);
        civ_item_family_home_img_3.setClickable(false);
        civ_item_family_home_img_1.setFocusable(false);
        civ_item_family_home_img_2.setFocusable(false);
        civ_item_family_home_img_3.setFocusable(false);
    }

    public void setTitle(String c) {
        tv_item_title.setText(c);
    }

    public void setTitle(int rid) {
        tv_item_title.setText(rid);
    }

    public void setCount(String c) {
        tv_item_count.setVisibility(VISIBLE);
        if (c.equals("0")) {
            tv_item_count.setVisibility(INVISIBLE);
        }
        tv_item_count.setText(c);
    }

    public void setNewData(List<String> datas, boolean isFeed) {
        civ_item_family_home_img_1.setVisibility(VISIBLE);
        civ_item_family_home_img_2.setVisibility(VISIBLE);
        civ_item_family_home_img_3.setVisibility(VISIBLE);
        tv_family_feed_nodata.setVisibility(INVISIBLE);
        tv_family_shortlive_nodata.setVisibility(INVISIBLE);
        String image1;
        String image2;
        String image3;
        if (datas.size() > 2) {
            image1 = datas.get(0);
            image2 = datas.get(1);
            image3 = datas.get(2);
            GlideUtil.loadRectangleBorderImage(civ_item_family_home_img_1, image1, R.dimen.size_2dp, R.color.bg_ff, R.dimen.roundxy);
            GlideUtil.loadRectangleBorderImage(civ_item_family_home_img_2, image2, R.dimen.size_2dp, R.color.bg_ff, R.dimen.roundxy);
            GlideUtil.loadRectangleBorderImage(civ_item_family_home_img_3, image3, R.dimen.size_2dp, R.color.bg_ff, R.dimen.roundxy);
        } else if (datas.size() > 1) {
            image1 = datas.get(0);
            image2 = datas.get(1);
            GlideUtil.loadRectangleBorderImage(civ_item_family_home_img_1, image1, R.dimen.size_2dp, R.color.bg_ff, R.dimen.roundxy);
            GlideUtil.loadRectangleBorderImage(civ_item_family_home_img_2, image2, R.dimen.size_2dp, R.color.bg_ff, R.dimen.roundxy);
            civ_item_family_home_img_3.setVisibility(GONE);
        } else if (datas.size() > 0) {
            image1 = datas.get(0);
            GlideUtil.loadRectangleBorderImage(civ_item_family_home_img_1, image1, R.dimen.size_2dp, R.color.bg_ff, R.dimen.roundxy);
            civ_item_family_home_img_2.setVisibility(GONE);
            civ_item_family_home_img_3.setVisibility(GONE);
        } else {
            civ_item_family_home_img_1.setVisibility(GONE);
            civ_item_family_home_img_2.setVisibility(GONE);
            civ_item_family_home_img_3.setVisibility(GONE);
            if (isFeed) {
                tv_family_feed_nodata.setVisibility(VISIBLE);
            } else {
                tv_family_shortlive_nodata.setVisibility(VISIBLE);
            }
        }
    }

    public void setCountHidden() {
        tv_item_count.setVisibility(INVISIBLE);
        tv_family_shortlive_in.setVisibility(GONE);
    }
}
